import { ajax } from '../../config/config.js';

class upload extends React.Component {
  constructor(props) {
    super(props)

    this.fileChang = this.fileChang.bind(this);
    this.uploadClick = this.uploadClick.bind(this);
  }


  fileChang(E) {
    if(E.target.files[0]) {
      const file = E.target.files[0];
      console.log('成功获取文件');
      console.log('文件名：' ,file.name);
      console.log('文件大小：' ,file.size);
      console.log('文件类型：' ,file.type);
      let formData = new FormData();
      // formData.append(this.props.key)
      // ajax({
      //   url: this.state.props,
      //   type: 'POST',
      //   data:
      //   success: function(){
      //
      //   },
      //   error: function() {
      //
      //   }
      // })
    }
  }

  uploadClick() {
    console.log(1);
    this.upload.click()
  }

  render() {
    return (
      <div className="upload">
        <input type='file' name="file" onChange={this.fileChang} ref={dom => this.upload = dom}></input>
        <button type="button" onClick={this.uploadClick} className="btn btn-success">上传</button>
      </div>
    )
  }
}

module.exports = upload;
